﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using Newtonsoft.Json;
using System.IO;

using NCT.Framework;

namespace VISS.Web.BackEnd {
    public class FormValidateUtils {
        public static void JsonValidate(ResultEnt result) {
            string _result = JsonConvert.SerializeObject(result);
            Return(_result);
        }

        public static void Return(string response) {
            HttpResponse httpResponse = HttpContext.Current.Response;

            httpResponse.ClearContent();
            httpResponse.ContentType = "application/json";
            httpResponse.Write(response);
            httpResponse.End();
        }

        public static void ReturnHTML(string response) {
            HttpResponse httpResponse = HttpContext.Current.Response;

            httpResponse.ClearContent();
            httpResponse.ContentType = "text/html";
            httpResponse.Write(response);
            httpResponse.End();
        }
    }

    public enum ValidationFailBy : int {
        system = -1,
        success = 0,
        user = 1
    }

    #region FieldValidateEntity
    public class ResultEnt {
        public ResultEnt() {
            Result = ValidationFailBy.success;
        }

        public ValidationFailBy Result { get; set; }
        [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
        public string Msg { get; set; }
        [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
        public List<FieldValidateEnt> FieldValidate { get; set; }
    }

    public class FieldValidateEnt {
        public FieldValidateEnt(string field, string title, string msg) {
            this.Field = field;
            this.Title = title;
            this.Msg = msg;
        }

        public string Field { get; set; }
        public string Title { get; set; }
        public string Msg { get; set; }
    }
    #endregion
}